import axios from "axios";
export const POST = async function(url, data) {
  let res = await axios({
    url,
    method: "POST",
    data: data,
    headers: {
      "content-type": "application/json"
    }
  });
  return res.data;
};

export const GET = async function(url, params) {
  let res = await axios({
    url,
    method: "GEt",
    params
  });
  return res.data;
};

axios.interceptors.request.use(
  config => {
    const token = localStorage.getItem("token");
    if (token) {
      config.headers.token = token;
    }
    // console.log(config);
    return config;
  },
  err => {
    return Promise.reject(err);
  }
);

axios.interceptors.response.use(
  response => {
    // console.log(response);
    return response;
  },
  error => {
    return Promise.reject(error.response);
  }
);
